import { hasOwn } from '../../shared/util'
import config from '../config'
const strats = config.optionMergeStrategies;
export function resolveAsset(
    options,
    type,
    id,
    warnMissing
  ) {
    /* istanbul ignore if */
    if (typeof id !== 'string') {
      return
    }
    const assets = options[type] || {}
    //取出components对应的组件模板
    console.log("取出components对应的组件模板")
    if (hasOwn(assets, id)) return assets[id]
    // const camelizedId = camelize(id)
    // if (hasOwn(assets, camelizedId)) return assets[camelizedId]
    // const PascalCaseId = capitalize(camelizedId)
    // if (hasOwn(assets, PascalCaseId)) return assets[PascalCaseId]
    // // fallback to prototype chain
    // const res = assets[id] || assets[camelizedId] || assets[PascalCaseId]
    // if (process.env.NODE_ENV !== 'production' && warnMissing && !res) {
    //   warn(
    //     'Failed to resolve ' + type.slice(0, -1) + ': ' + id,
    //     options
    //   )
    // }
    // return res
}
export function mergeOptions(
    parent,
    child,
    vm
) {
    if (typeof child === 'function') {
        child = child.options
    }
    //合并parent对象和child
    const options = {}
    let key
    for (key in parent) {
        mergeField(key)
    }
    for (key in child) {
        if (!hasOwn(parent, key)) {
          mergeField(key)
        }
    }
    function mergeField (key) {
        const strat = strats[key] || defaultStrat
        options[key] = strat(parent[key], child[key], vm, key)
    }
    return options
}
const defaultStrat = function (parentVal, childVal) {
    return childVal === undefined
      ? parentVal
      : childVal
}